package com.fgchen.study.thread;

import java.util.concurrent.Exchanger;

/**
 * Created by fgchen on 2017/7/20.
 */
public class ExchangerDemo {

    public static void main(String[] args) throws Exception {

        final Exchanger<String> exchanger = new Exchanger<>();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    String maininfo = exchanger.exchange("subthread info");
                    System.out.println("sub: " + maininfo);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();


        String subinfo = exchanger.exchange("mainthread info");
        System.out.println("main: " + subinfo);
    }

}
